# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2024/10/19
desc: 
sample: 
"""
import csv

import pytest
import requests


# def getcsvlist():
#     idlist=[]
#     with open('id.csv',encoding='utf-8') as f:
#         csv_reader = csv.reader(f)
#         next(csv_reader)
#         for line in csv_reader:
#             idlist.append(line)
#     return idlist
from utils import getcsvlist, getcsvlist_dict

# def getcsvlist_dict():
#     list = []
#     with open('id.csv', encoding="utf-8") as f:
#         csv_reader = csv.DictReader(f)
#         for line in csv_reader:
#             list.append(line)
#     return list

# print(getcsvlist_dict())

host = 'http://121.11.97.201:9088/pinter/com/'

@pytest.mark.flaky(reruns=3,reruns_delay=2) #延迟2秒 再重试 最多重试三次
@pytest.mark.parametrize("id,message,test",getcsvlist('id.csv')) #list(list)
def test_getSku(id,message,test):
   response = requests.get(url=f'{host}getSku?id={id}')
   print(response)
   assert response.status_code == 200
   res_dict = response.json()
   assert res_dict['message'] == message


@pytest.mark.flaky(reruns=3,reruns_delay=2) #延迟2秒 再重试 最多重试三次
@pytest.mark.parametrize("params",getcsvlist_dict('id.csv')) #list(dict)
def test_getSku2(params):
   id=params.get('id')
   response = requests.get(url=f'{host}getSku?id={id}')
   print(response)
   assert response.status_code == 200
   res_dict = response.json()
   assert res_dict['message'] == params.get('message')